<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class NoticeAction extends BaseAccountAction {

	//显示Notice
	public function index() {
		$this->init();
		$Notice = D('Notice');
		import("@.ORG.Util.Page");
		$Count = $Notice->where('user_id=' . $this->uid)->count();
		$Page = new Page($Count, 10);
		$show = $Page->show();
		$list = $Notice->where('user_id=' . $this->uid)->limit($Page->firstRow . ',' . $Page->listRows)->order('update_time desc')->select();
		foreach ($list as $key => $val) {
			$view = new View();
			if ($list[$key]['school_id']) {
				$school = get_shcool_info($list[$key]['school_id']);
				$view->assign("school_abbr", $school["school_abbr"]);
				$view->assign("school_name", $school['school_name']);
			}
			$view->assign("notice_id", (int) $list[$key]['notice_id']);
			$view->assign("school_id", (int) $list[$key]['school_id']);
			$view->assign("count", (int) $list[$key]['count']);
			$view->assign("tweets_id", (int) $list[$key]['tweets_id']);
			try {
				$data = json_decode($list[$key]['content'], true);
				foreach ($data as $key1 => $val1) {
					$view->assign($key1, $val1);
				}
			} catch (Exception $exc) {
				
			}
			if (file_exists(HTML_PATH . "/_notice/_" . (int) $list[$key]['type_id'] . ".html"))
				$list[$key]['content'] = $view->fetch(HTML_PATH . "/_notice/_" . (int) $list[$key]['type_id'] . ".html");
			else
				unset($list[$key]);
		}
		$this->assign('list', $list);
		$this->assign('page', $show);
		$this->display("Notice_index");
	}

	//显示单条
	public function show() {
		$id = (int) $_GET['id'];
		if ($id) {
			$notice = D("Notice")->find($id);
			$school = get_shcool_info($notice['school_id']);
			D("Notice")->where($id)->setField("status", 1);
			S("notice_new_" . $this->uid, null);

			$notice_type = D("Notice_type")->cache("notice_type")->where("status=1")->select();
			$notice_type = list_to_tree($notice_type, "type_id");
			$type = list_search($notice_type, array("type_id" => $notice["type_id"]));
			if (count($type) > 0) {
				if ($type[0]["cate_id"] == 0)
					redirect(__ROOT__ . "/" . $school["school_abbr"] . "/tweets/" . $notice["tweets_id"]);
				else {
					$data = json_decode($notice['content'], true);
					redirect(__ROOT__ . "/" . $school["school_abbr"] . "/tweets/" . $notice["tweets_id"] . "#comment-id-" . $data["comment_id"]);
				}
			}
		}
	}

}

?>
